﻿using Microsoft.AspNetCore.Mvc;
using RuoVea.DynamicWebApi;
using RuoVea.ExSugar;
using RuoVea.ExUtil;
using RuoVea.OmiApi.Article.Entitys;
using RuoVea.OmiApi.Article.Service.Dto;
using System.ComponentModel;

namespace RuoVea.OmiApi.Article.Service;
/// <summary>
/// 分类管理 🔷
/// </summary>
[ApiExplorerSettings(GroupName = "art")]
public class CategoryArticleService : IApplicationService
{
    private readonly SugarRepository<ArtCategory> _thisRepository;

    /// <summary>
    /// 参数配置表
    /// </summary>
    /// <param name="thisRepository"></param>
    public CategoryArticleService(SugarRepository<ArtCategory> thisRepository )=> _thisRepository = thisRepository;
     
    /// <summary>
    /// 获取列表🔹
    /// </summary>
    /// <returns></returns>
    [DisplayName("获取列表")]
    public List<ArtCategoryArticle> GetList(CategoryParam data)
    {
        var query = _thisRepository.AsQueryable()
            .InnerJoin<ArtCategoryArticle>((x, c) => x.Id == c.CategoryId)
            .WhereIF(data.Code.NotNullOrWhiteSpace(), x => x.Code.Contains(data.Code))
            .WhereIF(data.Name.NotNullOrWhiteSpace(), x => x.Name.Contains(data.Name))
            .OrderByDescending(x => x.CreateTime)
            .Select((x, c) => c);
        return query.ToPageList(data.PageNo, data.PageSize);
    }
}